package com.leather.admin.vo;

import java.util.Date;

import com.leather.admin.entity.Admin;
import com.leather.common.result.CodeMsg;
import com.leather.common.result.Result;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

@Data
public class AdminVo implements Serializable {

    private String adminName;

    private String password;

    private String adminDesc;

    private Integer roleId;


    /**
     * 基础的密码 用户名校验
     *
     * @return
     */
    public Result validate() {
        if (StringUtils.isBlank(adminName)) {
            return Result.error(CodeMsg.EMPTY_ADMINNAME);
        }
        if (StringUtils.isBlank(password)) {
            return Result.error(CodeMsg.EMPTY_ADMINPASSWORD);
        }
        if (password.length() <= 6) {
            return Result.error(CodeMsg.ERROR_PASSWORD_LENGTH);
        }
        return Result.success(trancefer());
    }


    public Result validateChange() {

        return validate();
    }

    public Result validateAdd() {

        if (StringUtils.isBlank(adminDesc)) {
            return Result.error(CodeMsg.EMPTY_ADMINDESC);
        }
        return validate();
    }

    public Admin trancefer() {
        Admin admin = new Admin();
        admin.setId(0);
        admin.setAdminName(adminName);
        admin.setPassword(password);
        admin.setCreateTime(new Date());
        admin.setRoleId(roleId);
        admin.setAdminDesc(adminDesc);
        return admin;
    }

}
